package com.tchintech.pay.adapter;

import android.content.Context;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.tchintech.pay.R;
import com.tchintech.pay.model.entity.PayFees;

import java.util.List;

/**
 * Created by Administrator on 2017/8/22 0022.
 * <p>
 * 便民服务
 * 支付界面数据展示的公共适配器
 */

public class RecyclePayAdapter extends RecyclerView.Adapter<RecyclePayAdapter.MyViewHolde> {

    private Context context;
    private List<PayFees> list;
    private boolean flag;

    public RecyclePayAdapter(Context context, List<PayFees> list, boolean flag) {
        this.context = context;
        this.list = list;
        this.flag = flag;
    }

    public void setData(boolean flag) {
        this.flag = flag;
        notifyDataSetChanged();

    }

    //设置item的布局
    @Override
    public RecyclePayAdapter.MyViewHolde onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_recyclepay, parent, false);
        RecyclePayAdapter.MyViewHolde viewHolder = new RecyclePayAdapter.MyViewHolde(view);
        return viewHolder;
    }

    //对item的数据绑定
    @Override
    public void onBindViewHolder(RecyclePayAdapter.MyViewHolde holder, final int position) {
        final PayFees payFees = list.get(position);
        holder.te_je.setText(payFees.getAliasName());
        if (flag) {
            holder.real_pay.setBackground(ContextCompat.getDrawable(context, R.drawable.recycle_pay_select));
            holder.te_je.setTextColor(ContextCompat.getColor(context, R.color.colorWx));
        } else {
            holder.real_pay.setBackground(ContextCompat.getDrawable(context, R.drawable.recycle_pay_bk));
            holder.te_je.setTextColor(ContextCompat.getColor(context, R.color.black));

        }
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mOnItemClickLitener.onItemClick(payFees, position);
            }
        });

    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    class MyViewHolde extends RecyclerView.ViewHolder {
        RelativeLayout real_pay;
        TextView te_je;

        public MyViewHolde(View itemView) {
            super(itemView);
            real_pay = (RelativeLayout) itemView.findViewById(R.id.real_pay);
            te_je = (TextView) itemView.findViewById(R.id.te_je);

        }
    }

    public interface OnItemClickLitener {
        void onItemClick(PayFees payFees, int position);
    }

    private RecyclePayAdapter.OnItemClickLitener mOnItemClickLitener;

    public void setOnItemClickLitener(RecyclePayAdapter.OnItemClickLitener mOnItemClickLitener) {
        this.mOnItemClickLitener = mOnItemClickLitener;
    }
}
